﻿<@pp.dropOutputFile/>
<#include "common/util.ftl">
<#-- iterate table list-->
<#list doc.tables as table>

<#-- generate package name -->
<#assign app = doc.artifactid?replace(".", "/")>
<#assign package = table.moduleid?replace(".", "/")>
<#assign fileName = table.name?cap_first>
<@pp.changeOutputFile name = "/" + package  + "/DataSource.vb"/>
<#assign package = table.moduleid?replace("/", ".")>
Imports System.Data.SQLite

Public Class DataSource
    Shared _connection As IDbConnection = Nothing
    Private Shared log As log4net.ILog = log4net.LogManager.GetLogger(Reflection.MethodBase.GetCurrentMethod().DeclaringType)

    Private Sub New()

    End Sub

    Public Shared Function getInstance() As IDbConnection
        If _connection Is Nothing Then
            _connection = connect()
        End If
        Return _connection
    End Function

    Private Shared Function connect() As IDbConnection
        Dim connection As SQLiteConnection = Nothing
        connection = New SQLiteConnection()
        Dim connectionString As SQLiteConnectionStringBuilder
        connectionString = New SQLiteConnectionStringBuilder()
        connectionString.DataSource = "db1.db"
        Try
            connection.ConnectionString = connectionString.ToString()
            connection.Open()
        Catch ex As Exception
            log.Error(ex.Message)
        End Try

        Return IIf(connection.State = ConnectionState.Open, connection, Nothing)
    End Function

End Class
</#list>